package com.heima.behavior.controller.v1;

import com.heima.behavior.service.*;
import com.heima.model.behavior.dtos.*;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 29143
 */
@RestController
@RequestMapping("/api/v1")
public class ApBehaviorEntryController {

    @Autowired
    ApLikesBehaviorService apLikesBehaviorService;

    @Autowired
    private ApReadBehaviorService apReadBehaviorService;

    @Autowired
    private ApUnlikeBehaviorService apUnlikeBehaviorService;

    @Autowired
    private ApCollectionBehaviorService apCollectionBehaviorService;

    @Autowired
    private ApArticleBehaviorService apArticleBehaviorService;

    /**
     * 保存或取消点赞
     * @param dto
     * @return
     */
    @PostMapping("/likes_behavior")
    public ResponseResult likes( @RequestBody LikesBehaviorDTO dto){
        return apLikesBehaviorService.like(dto);
    }

    /**
     * 记录阅读行为
     * @param dto
     * @return
     */
    @PostMapping("/read_behavior")
    public ResponseResult read(@RequestBody ReadBehaviorDTO dto){
        return apReadBehaviorService.readBehavior(dto);
    }

    /**
     * 保存或取消不喜欢
     * @param dto
     * @return
     */
    @PostMapping("/un_likes_behavior")
    public ResponseResult unLikes(@RequestBody UnLikesBehaviorDTO dto){
        return apUnlikeBehaviorService.unlikeBehavior(dto);
    }

    /**
     * 收藏 或 取消收藏行为
     * @param dto
     * @return
     */
    @PostMapping("/collection_behavior")
    public ResponseResult collection(@RequestBody CollectionBehaviorDTO dto){
        return apCollectionBehaviorService.collectBehavior(dto);
    }

    /**
     * 加载文章详情, 数据回显
     * @param dto
     * @return
     */
    @PostMapping("/article/load_article_behavior")
    public ResponseResult loadArticle (@RequestBody ArticleBehaviorDTO dto){
        return apArticleBehaviorService.loadArticleBehavior (dto);
    }
}
